﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;

public partial class BalanceCenter_EditUserNet : PageBase
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!this.IsPostBack)
        {
            this.lbUserName.Text = _User.RealityName;

            long ToUserID = ShoveEL._Convert.StrToLong(Request["id"], -1);
            if (ToUserID > 0)
            {
                User tu = new User();
                tu.ID = ToUserID;

                string Return = "";
                int Result = tu.GetUserInfoByID(ref Return);

                if (Result != 0)
                {
                    ShoveEL._Web.JavaScript.Alert(this.Page, Return);

                    return;
                }

                if (_User.ID != tu.SurrogateID)
                {
                    PublicFunction.GoError(ErrorNumber.Unknow, "对不起，你没有修改该用户网络位置信息", this.GetType().BaseType.FullName);

                    return;
                }

                tbUserName.Text = tu.Name;
                tbUserName.ReadOnly = true;

                if ((tu.LR == 1) || (tu.LR == 2))
                {
                    if (tu.LR == 1)
                    {
                        rbL.Checked = true;
                        rbR.Checked = false;
                    }

                    if (tu.LR == 2)
                    {
                        rbL.Checked = false;
                        rbR.Checked = true;
                    }
                }

                User Commend = new User();
                Commend.ID = tu.CommendID;

                Return = "";
                Result = Commend.GetUserInfoByID(ref Return);
                if (Result != 0)
                {
                    ShoveEL._Web.JavaScript.Alert(this.Page, "推荐人消费ID不存在。");

                    return;
                }

                User Parent = new User();
                Parent.ID = tu.ParentID;
                Return = "";
                Result = Parent.GetUserInfoByID(ref Return);
                if (Result != 0)
                {
                    ShoveEL._Web.JavaScript.Alert(this.Page, "网络位置上级消费ID不存在。");

                    return;
                }

                tbCommendUser.Text = Commend.Name;

                tbParentUser.Text = Parent.Name;
            }
            else
            {
                PublicFunction.GoError(ErrorNumber.Unknow, "参数错误", this.GetType().BaseType.FullName);

                return;
            }

            this.ibSubmit.Attributes.Add("onclick", "return confirm('" + System.Web.HttpUtility.HtmlEncode("您确信输入的数据无误，并且立即充值吗？") + "');");
        }
    }

    #region Web 窗体设计器生成的代码

    override protected void OnInit(EventArgs e)
    {
        isRequestLogin = true;
        SecondLevelPassword = true;
        RequestLoginPage = "BalanceCenter/EditUserNet.aspx";

        base.OnInit(e);
    }

    #endregion

    protected void ibSubmit_Click(object sender, ImageClickEventArgs e)
    {
        if (tbUserName.Text.Trim() == "")
        {
            ShoveEL._Web.JavaScript.Alert(this.Page, "请输入消费ID。");
            return;
        }

        User tu = new User();
        tu.Name = ShoveEL._Convert.ToDBC(tbUserName.Text.Trim());
        string Return = "";
        int Result = tu.GetUserInfoByName(ref Return);
        if (Result != 0)
        {
            ShoveEL._Web.JavaScript.Alert(this.Page, Return);

            return;
        }

        User Commend = new User();
        Commend.Name = tbCommendUser.Text.Trim();

        Return = "";
        Result = Commend.GetUserInfoByName(ref Return);
        if (Result != 0)
        {
            ShoveEL._Web.JavaScript.Alert(this.Page, "推荐人消费ID不存在。");

            return;
        }

        User Parent = new User();
        Parent.Name = tbParentUser.Text.Trim();
        Return = "";
        Result = Parent.GetUserInfoByName(ref Return);
        if (Result != 0)
        {
            ShoveEL._Web.JavaScript.Alert(this.Page, "网络位置上级消费ID不存在。");

            return;
        }

        int LR = 0;
        if (this.rbL.Checked == true)
        {
            LR = 1;
        }
        else if (this.rbR.Checked == true)
        {
            LR = 2;
        }

        Result = 0;
        Return = "";
        if (DAL.Procedures.P_EditUserNet.Call(tu.ID, Parent.ID, LR, Commend.ID, cbAutoNext.Checked, ref Result, ref Return) < 0)
        {
            PublicFunction.GoError(ErrorNumber.DataReadWrite, "数据读写错误", this.GetType().BaseType.FullName);

            return;
        }

        if (Result != 0)
        {
            ShoveEL._Web.JavaScript.Alert(this.Page, Return);
            return;
        }

        //写入操作日志
        OperationLog Log = new OperationLog();

        Log._Memo = _User.Name + "修改" + tu.Name + "网络位置";
        Log._OpDateTime = DateTime.Now;
        Log._UserID = _User.ID;
        Log._UserIP = System.Web.HttpContext.Current.Request.UserHostAddress;

        Log.Add();
        //操作日志写入完成


        ShoveEL._Web.JavaScript.Alert(this.Page, "修改成功!!!!");
    }
}